home *** CD-ROM | disk | FTP | other *** search
- /*
- ** PGP5GUI - A GUI using Magic User Interface v3.8
- **
- ** Copyright 23-JUNE-1998 by Stefan Zakarias, All Rights Reserved.
- **
- ** This source code is released as FREEWARE - Use it for whatever you like,
- ** as long as NO financial reward is gained by you for such usage.
- **
- ** If you use any parts of the this source code for anything, give ME credit
- ** wherever credit is due, please ;-)
- */
-
- /*
- ** Generate key-info strings for a MUI ListView...
- **
- ** From a text output file we previously created using "PGPK -l >PGP5Keys":
- **
- **
- ** Type Bits KeyID Created Expires Algorithm Use
- ** pub 1024 E06CBF11 1997-04-18 ---------- RSA Sign and Encrypt
- ** uid Shane Cracknell <shane@amitar.com.au>
- **
- ** pub 1024 04A76854 1997-10-24 ---------- DSS Sign and Encrypt
- ** sub 2048 64B2CFEC 1997-10-24 ---------- Diffie-Hellman
- ** uid Shanel Cracknell <Shane@amitar.com.au>
- **
- ** sec+ 1024 CA214F18 1997-10-18 ---------- DSS Sign and Encrypt
- ** sub 2048 D6F69DA2 1997-10-18 ---------- Diffie-Hellman
- ** uid Stefan L. Zakarias <stef@amitar.com.au>
- **
- ** sec 1024 E6042DD9 1997-08-24 ---------- RSA Sign and Encrypt
- ** uid Stefan Zakarias <stef@amitar.com.au>
- **
- ** 4 matching keys found
- **
- ** >>> OR WITH UNIX PGP5.0i - "Final"... <<<
- **
- ** Type Bits KeyID Created Expires Algorithm Use
- ** pub 1024 0xE06CBF11 1997-04-18 ---------- RSA Sign and Encrypt
- ** uid Shane Cracknell <shane@amitar.com.au>
- **
- ** pub 1024 0x04A76854 1997-10-24 ---------- DSS Sign and Encrypt
- ** sub 2048 0x64B2CFEC 1997-10-24 ---------- Diffie-Hellman
- ** uid Shanel Cracknell <Shane@amitar.com.au>
- **
- ** sec+ 1024 0xCA214F18 1997-10-18 ---------- DSS Sign and Encrypt
- ** sub 2048 0xD6F69DA2 1997-10-18 ---------- Diffie-Hellman
- ** uid Stefan L. Zakarias <stef@amitar.com.au>
- **
- ** sec 1024 0xE6042DD9 1997-08-24 ---------- RSA Sign and Encrypt
- ** uid Stefan Zakarias <stef@amitar.com.au>
- **
- ** 4 matching keys found
- **
- **
- ** We'll extract a line with the format of "Algo KeyID Created UserID"
- **
- ** We then write lines, like the following, to the temporary file "T:selected".
- **
- ** RSA E06CBF11 1997-04-18 Shane Cracknell <shane@amitar.com.au>
- ** DSS 04A76854 1997-10-24 Shanel Cracknell <Shane@amitar.com.au>
- ** DSS CA214F18 1997-10-18 Stefan L. Zakarias <stef@amitar.com.au>
- ** RSA E6042DD9 1997-08-24 Stefan Zakarias <stef@amitar.com.au>
- */
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <dos/dos.h>
- #include <utility/tagitem.h>
- #include <dos/exall.h>
-
- #include <string.h>
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <clib/alib_stdio_protos.h>
-
- /* Include GUI stuff */
- #include "SelPGPKeyGUI.h"
-
- /* Parser modes */
- #define PUB_KEY 1
- #define GET_UID 2
-
- /* The key-info table (1024 keys max.) */
- char *keystable[1025];
-
- /*
- ** Generates the strings for the listview.
- ** Returns: 0 = No error, -1 = filename not found.
- */
- int
- GenerateKeyStrings(char *filename)
- {
- char *buffer;
- char *indptr;
-
- char algobuff[ALGO_SIZE]; /* Buffer for algorithm type */
- char keyIDbuff[KEYID_SIZE]; /* Buffer for key ID */
- char createdbuff[CREATED_SIZE]; /* Buffer for created date */
- char userIDbuff[USERID_SIZE]; /* Buffer for user ID. */
-
- char parsedline[BUFFER_SIZE]; /* Buffer for parsed line */
- char linebuff[USERID_SIZE]; /* Buffer for incoming line */
-
- BPTR filelock, filehandle;
-
- int i, len, keynum = 0, parsemode = PUB_KEY;
-
- /* Quick-check to see if the file exists! */
- filelock = Lock(filename, ACCESS_READ);
-
- /* Did we get a lock on that file? */
- if (filelock)
- {
- /* File was found... We can (have to?) unlock it now */
- UnLock(filelock);
-
- /*
- ** We have a record of possibly key-info..
- ** Open key-info file so we can access it
- */
- filehandle = Open(filename, MODE_OLDFILE);
-
- /* Did DOS give us the O.K. to read it? */
- if (filehandle)
- {
- /*
- ** DOS says it's OK to use!
- ** Read a string of upto 255 bytes from the record into 'linebuff'.
- ** 'buffer' is a pointer to 'linebuff' or NULL if EOF/ERROR.
- ** We break out of loop on NULL/EOF/ERROR.
- ** You need to use IOErr() to see if EOF or ERROR.
- */
-
- /* Free up any previously initialised 'keystable[]' memory */
- for (i = 0; i < 1024; i++)
- {
- if (keystable[i])
- {
- FreeVec(keystable[i]);
- keystable[i] = 0;
- }
- }
-
- buffer = linebuff;
-
- /* While the buffer has something... */
- while (buffer)
- {
- /* Get next line */
- buffer = FGets(filehandle, linebuff, (USERID_SIZE - 1));
-
- /* Get length of line */
- len = strlen(buffer);
-
- /* If not empty line and have less than 1025 entries... */
- if ((len > 3) && (keynum < 1024))
- {
- /* Get info from the lines according to parse-mode */
- switch (parsemode)
- {
- case PUB_KEY:
- /*
- ** We check for 'pub' or 'sec' in first 3 chars. of a line.
- ** When either of these is found, we do some processing and
- ** go on to GET_UID.
- */
- /*
- ** Put a terminating NULL at 4th. char. of buffer...
- ** We only have to check the 1st. 3 chars. of the line next!
- */
-
- *(buffer + 3) = NULL;
-
- /* Get a copy of buffer address */
- indptr = buffer;
-
- /* Check first 3 chars. for 'pub' or 'sec' */
- if ((strncmp(indptr, "pub", 3) == 0) ||
- (strncmp(indptr, "sec", 3) == 0))
- {
- /* Point to beginning of Key Size (Bits) */
- indptr += 5;
- *(indptr + 4) = NULL; /* Null terminate string */
-
- /* Point to beginning of KeyID */
- indptr += 5;
-
- if (*(indptr + 1) == 'x')
- {
- /* KeyID starts with '0x'... */
- *(indptr + (KEYID_SIZE - 1)) = NULL; /* Null terminate string */
-
- /* Get key's ID Number ('0x' prefixed) */
- strcpy(keyIDbuff, indptr);
-
- /* Point to the beginning of 'Created' date */
- indptr += KEYID_SIZE;
- }
- else
- {
- /* KeyID does NOT start with '0x'... */
- *(indptr + (KEYID_SIZE - 3 )) = NULL; /* Null terminate string */
-
- /* Get key's ID Number (not '0x' prefixed) */
- sprintf(keyIDbuff, "0x%s", indptr);
-
- /* Point to the beginning of 'Created' date */
- indptr += (KEYID_SIZE - 2);
- }
-
- *(indptr + (CREATED_SIZE - 1)) = NULL; /* Null terminate string */
-
- /* Get key's created date */
- strcpy(createdbuff, indptr);
-
- /* Point to beginning of 'Expires' date */
- indptr += 11;
- *(indptr + 10) = NULL; /* Null terminate string */
-
- indptr += 11; /* Point to beginning of 'Algo' */
- *(indptr + (ALGO_SIZE - 1)) = NULL; /* Null terminate string */
-
- /* Get key's algorithm type */
- strcpy(algobuff, indptr);
-
- /* Next mode... */
- parsemode = GET_UID;
- }
-
- break;
-
- case GET_UID:
- /*
- ** We've just moved to a new line...
- ** We check for 'uid' in first 3 chars. of a line.
- ** When this is found, we store the rest of the line.
- ** Then we go back to parsing for PUB_KEY.
- */
- /*
- ** Put a terminating NULL at 4th. char. of buffer...
- ** We check only first 3 chars. of the line next.
- */
-
- *(buffer + 3) = NULL;
- indptr = buffer; /* Get a copy of buffer address */
-
- /* Check first 3 chars. for 'uid' */
- if ((strncmp(indptr, "uid", 3) == 0))
- {
- /* Point to beginning of user ID */
- indptr += 5;
-
- len = strlen(indptr);
- *(indptr + (len - 1)) = NULL;
-
- /* Get key's user ID */
- strcpy(userIDbuff, indptr);
-
- /* Build up final line */
- sprintf(parsedline,"%s %s %s %s",
- algobuff,keyIDbuff,createdbuff,userIDbuff);
-
- /* Get length of built line */
- len = strlen(parsedline);
-
- /* Does line have something? */
- if (len)
- {
-
- /* Allocate memory and store pointer for line */
- keystable[keynum] = AllocVec(len+1, MEMF_PUBLIC|MEMF_CLEAR);
-
- /* Copy built line to allocated memory */
- strcpy(keystable[keynum], parsedline);
-
- /* Increment array pointer */
- keynum++;
- }
-
- /* Next mode... */
- parsemode = PUB_KEY;
- }
-
- break;
- }
- }
- }
-
- /* Finished with the file... */
- Close(filehandle);
-
- /* Store a NULL to show end of entries */
- keystable[keynum] = 0;
-
- return (0); /* Return - No Error */
- }
- }
-
- return (-1); /* Return - Error! */
- }
-